package com.waiting.clone;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/7
 **/
public class Main {
    public static void main(String[] args) {
        Person person = new Person();
        person.print();
        System.out.println("__________");
        Person personTwo = null;
        try {
            personTwo = (Person) person.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        personTwo.setYear(2020);
        personTwo.print();
        System.out.println("__________");
        person.print();
    }

}

class Person implements Cloneable {
    String name;
    int age;
    Integer year;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Person() {
        this.name = "waiting";
        this.age = 20;
        year = new Integer(2019);
    }

    public void print() {
        System.out.println("name=" + name);
        System.out.println("age=" + age);
        System.out.println("year=" + year);
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}